﻿using Rex.Assignment.Application.AppUsers.Dtos;
using Rex.Assignment.Application.AppUsers.Pos;
using Rex.Assignment.Common;
using Rex.Assignment.Domain.DomainService;
using Rex.Assignment.Domain.Models.Entitys;

namespace Rex.Assignment.Application.AppUsers.Impl
{
    /// <summary>
    /// 登录
    /// </summary>
    /// <remarks>
    /// @创 建 者：Rex
    /// @创建日期：2021/2/21 15:53:26
    /// </remarks>
    public class LoginService : ILoginService
    {
        private readonly ILoginDomainService _loginDomainService;

        public LoginService(ILoginDomainService loginDomainService)
        {
            _loginDomainService = loginDomainService;
        }

        /// <summary>
        /// 验证登录
        /// </summary>
        /// <param name="loginVerification">登录验证参数</param>
        /// <returns></returns>
        public DataResult<SysUserDto> VerificationLogin(LoginVerificationPo loginVerification)
        {
            var sysUseResult = _loginDomainService.VerificationLogin(loginVerification.LoginID, loginVerification.LoginPwd);
            SysUserDto sysUserDto = sysUseResult.Data.MapTo<SysUser, SysUserDto>();
            DataResult<SysUserDto> dataResult = new DataResult<SysUserDto>()
            {
                Code = sysUseResult.Code,
                Msg = sysUseResult.Msg,
                Data = sysUserDto,
                Count = sysUseResult.Count
            };
            return dataResult;
        }
    }
}
